package org.demo.biz.impl;

import java.text.ParseException;
import java.util.List;

import org.demo.biz.IReporterBiz;
import org.demo.dao.ICstCustomerDAO;
import org.demo.dao.ICstServiceDAO;
import org.demo.dao.IOrderDao;
import org.demo.dao.IProductDAO;
import org.demo.entity.CstCustomer;
import org.demo.entity.CstService;
import org.demo.entity.Orders;
import org.demo.entity.Product;
import org.demo.entity.Storage;

public class ReporterBizImpl implements IReporterBiz {

	IOrderDao orderDao = null;
	ICstCustomerDAO cstCustomerDao=null;
	ICstServiceDAO serviceDAO=null;
	IProductDAO productDAO=null;
	public List<Orders> findOrderInfo(String cstName, String year) {
		// TODO Auto-generated method stub
		if (year=="") {
			year=null;
		}
		try {
			return orderDao.findList(cstName, year);
		} catch (ParseException e) {
			// TODO Auto-generated catch block
			e.printStackTrace();
		}
		 return null;
	}
	
	public List<CstCustomer> findCstCustomers(String byWhat) {
		if (byWhat==null || byWhat=="") {
			byWhat="custLevel";
		}
		List<CstCustomer> list=cstCustomerDao.findCstCustomers(byWhat);
		return list;
	}
	
	public List<CstService> findCstServices(String year) {

		if (year=="") {
			year=null;
		}
		return serviceDAO.findCstServices(year);
		 
	}
	
 
	
	public IOrderDao getOrderDao() {
		return orderDao;
	}
	public void setOrderDao(IOrderDao orderDao) {
		this.orderDao = orderDao;
	}

	public ICstCustomerDAO getCstCustomerDao() {
		return cstCustomerDao;
	}

	public void setCstCustomerDao(ICstCustomerDAO cstCustomerDao) {
		this.cstCustomerDao = cstCustomerDao;
	}

	public ICstServiceDAO getServiceDAO() {
		return serviceDAO;
	}

	public void setServiceDAO(ICstServiceDAO serviceDAO) {
		this.serviceDAO = serviceDAO;
	}

	

	public IProductDAO getProductDAO() {
		return productDAO;
	}

	public void setProductDAO(IProductDAO productDAO) {
		this.productDAO = productDAO;
	}

	public Integer countProducts(int pageNo, int pageSize, Product product) {
		
		if (product.getProdName()==null) {
			product.setProdName("");
		}
		if (product.getProdType()==null) {
			product.setProdType("");
		} 
		if (product.getProdBatch()==null) {
			product.setProdBatch("");
		}
		return	productDAO.countProducts(pageNo, pageSize, product);
		 
	}

	public List<Product> findProducts(int pageNo, int pageSize, Product product) {
		// TODO Auto-generated method stub
		if (product.getProdName()==null) {
			product.setProdName("");
		}
		if (product.getProdType()==null) {
			product.setProdType("");
		} 
		if (product.getProdBatch()==null) {
			product.setProdBatch("");
		}
		
		return productDAO.findProducts(pageNo, pageSize, product);
	}

	public Integer countStorages(int pageNo, int pageSize, Storage storage) {

		if (storage.getStkWarehouse()==null) {
			storage.setStkWarehouse("");
		}
		 
		
		return productDAO.countStorages(pageNo, pageSize, storage);
		  
	}

	public List<Storage> findStorages(int pageNo, int pageSize, Storage storage) {

		if (storage.getStkWarehouse()==null) {
			storage.setStkWarehouse("");
		}
		
		return productDAO.findStorages(pageNo, pageSize, storage);
		 
	}

}
